package com.lin.cloud.disk.entity.response;

import cn.hutool.core.bean.BeanUtil;
import com.lin.cloud.disk.entity.dto.PermissionDTO;
import com.lin.cloud.disk.entity.pojo.Permission;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 所有的权限列表
 *
 * @author ljc
 * @date 2021/1/12 9:27
 */
@Data
public class PermissionGroupListResponse {

    @ApiModelProperty(value = "操作级权限", name = "operatorPermissionList")
    private List<Permission> operatorPermissionList;

    @ApiModelProperty(value = "页面级权限", name = "pagePermissionList")
    private List<Permission> pagePermissionList;

    @ApiModelProperty(value = "系统级权限", name = "systemPermissionList")
    private List<Permission> systemPermissionList;

    public PermissionGroupListResponse(List<Permission> permissionList) {
        // 不存在或者权限为空 则全部为空数组
        if (CollectionUtils.isEmpty(permissionList)) {
            this.operatorPermissionList = Collections.EMPTY_LIST;
            this.pagePermissionList = Collections.EMPTY_LIST;
            this.systemPermissionList = Collections.EMPTY_LIST;
        } else {
            // 存在则新建数组并加入
            this.operatorPermissionList = new ArrayList<>();
            this.pagePermissionList = new ArrayList<>();
            this.systemPermissionList = new ArrayList<>();
            for (Permission permission : permissionList) {
                if (0 == permission.getPermissionType()) {
                    this.operatorPermissionList.add(permission);
                } else if (1 == permission.getPermissionType()) {
                    this.pagePermissionList.add(permission);
                } else if (2 == permission.getPermissionType()) {
                    this.systemPermissionList.add(permission);
                }
            }
        }
    }

}
